ptrplus
Ptrplus is a library that adds additional functionality around raw pointers.
Conversions
Ptrplus provides traits to convert between raw pointers and safer Rust pointer types. AsPtr
, IntoRaw
,
and FromRaw
provide common traits for types that implement as_ptr
, into_raw
, and from_raw
respectively.
Of note, these traits also have implementations for Option
to handle nullable raw pointers.
Examples
use AsPtr;
let x: &u32 = &5;
let y: *const u32 = x.as_ptr;
unsafe
use AsPtr;
let x = 5;
let o1: = None;
let o2: = Some;
assert!;
assert!;
unsafe
use IntoRaw;
let x: = Box new;
let y: *mut u32 = into_raw;
unsafe
use ;
let o1: = None;
let o2: = Some;
let p1: *mut u32 = o1.into_raw;
let p2: *mut u32 = o2.into_raw;
assert!;
assert!;
unsafe